package com.aabbc.cinema.runner;

import com.aabbc.cinema.config.QueryConfig;
import com.aabbc.cinema.query.Query;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;

/**
 * CinemaApplicationRunner
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2020-03-24 9:39
 * @blame Team
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(QueryConfig.class)
public class CinemaApplicationRunner implements ApplicationRunner {

    @Resource
    Query query;

    /**
     * Callback used to run the bean.
     *
     * @param args incoming application arguments
     * @throws Exception on error
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        CompletableFuture.runAsync(() -> query.run());
    }
}
